package com.edu.oracle.controller;

import com.edu.oracle.service.LoginService;
import com.edu.oracle.service.impl.LoginServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//注入声明  注解
@WebServlet(name = "LoginServlet")
public class LoginServletController extends HttpServlet {
    //new loginService类
    LoginService loginService = new LoginServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("login登录请求");//控制台输出

        //1.获取前端数据
        String user=request.getParameter("sno");
        String password=request.getParameter("sclass");

        //2.调用service的登录方法
        Boolean bl = loginService.login(user,password);

        //3.返回数据给前端
        if(bl){
            response.sendRedirect("index.jsp");
        }else {
            response.sendRedirect("login.html");
        }


        /*
        1.转发 request
        2.重定向   response
        request.getRequestDispatcher("index.jsp").forward(request,response);
        response.sendRedirect("index.jsp");
        */



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
